package executeEngine.methodInvoke.dynamicDispatch;

abstract class Animal {
    abstract void say();
}

class Dog extends Animal {
    @Override
    void say() {
        System.out.println("I am dog");
    }
}

class Cat extends Animal {
    @Override
    void say() {
        System.out.println("I am cat");
    }
}

/**
 * 动态分派
 */
public class Demo {
    public static void main(String[] args) {
        Animal a1 = new Dog();
        Animal a2 = new Cat();
        a1.say();
        a2.say();
        a1 = new Cat();
        a1.say();
    }
}
